package haonan3344.localbbs.gui;

import static org.junit.Assert.assertTrue;

import java.sql.SQLException;

import haonan3344.localbbs.conf.Settings;
import haonan3344.localbbs.core.User;
import haonan3344.localbbs.db.UserDb;
import haonan3344.localbbs.parser.UserParser;
import haonan3344.localbbs.spider.ScSpider;

public class TestFechUsers {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Settings.init();

		ScSpider ssp= new ScSpider();
		assertTrue(ssp.login(Settings.getLoginUsername(), Settings.getLoginPassword()));
		
		UserParser up = new UserParser();
		
		try {
			UserDb udb = new UserDb();
			udb.clear();
			
			for(int i=1;i<=23495;i++){
				try {
					User u = up.parse(ssp.getPage("http://www.cctvdream.com.cn/bbs/home.php?mod=space&uid="+i+"&do=profile&mobile=no"));
					if(u==null){
						System.err.println("Uid "+i+"\t error!");
						continue;
					}else{
						System.out.println("Uid "+i+"\t ok!");
					}
					udb.AddUser(u);
				}
				catch(Exception e){
					e.printStackTrace();
				}
			}
			
		} catch (IllegalStateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
